//
// Created by cheng on 2021/02/01.
//
#include "Sort.h"

int selectionSort(int* A, int len);

int main() {
    int arr[9] = {9,8,7,6,5,4,3,2,1};
    Sort::printArray(arr, 9);
    auto sw = selectionSort(arr, 9);
    Sort::printArray(arr, 9);
    cout << sw << endl;
}

int selectionSort(int *A, int len) {
    int i, j, t, sw = 0, minJ;
    for(i = 0; i < len-1; i++) {
        minJ = i;
        for(j = i; j < len; ++j) {
            if(A[j] < A[minJ]) {
                minJ = j;
            }
        }
        if (i != minJ) {
            swap(A[i], A[minJ]);
            sw++;
        }
        Sort::printArray(A, 9);
    }
    return sw;
}

